package com.wolf.controller;

import com.wolf.pojo.Wl_commodity_brand_tag;
import com.wolf.service.Wl_commodity_brand_tagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.wolf.util.execl;
import com.wolf.util.Math;

import java.util.Date;
import java.util.List;

@Controller
@ComponentScan
public class Wl_commodity_brand_tagController {

    @Autowired
    Wl_commodity_brand_tagService wl_commodity_brand_tagService;

    /***
     * 查询所有品牌标签信息
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_brand_tag_getAll")
    public String getAll(ModelMap modelMap){

        List<Wl_commodity_brand_tag> wl_commodity_brand_tagList=this.wl_commodity_brand_tagService.getAll();

        modelMap.addAttribute("wl_commodity_brand_tagList",wl_commodity_brand_tagList);

        return "table_wl_commodity_brand_tag";
    }

    /***
     * 查询所有品牌标签然后跳转至品牌新增页面
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_brand_tag_toBrandInsert")
    public String toBrandInsert(ModelMap modelMap){

        List<Wl_commodity_brand_tag> wl_commodity_brand_tagList=this.wl_commodity_brand_tagService.getAll();

        modelMap.addAttribute("wl_commodity_brand_tagList",wl_commodity_brand_tagList);

        return "wl_commodity_brand_insert";
    }

    /***
     * 多条件模糊查询品牌标签信息
     * @param tagName
     * @param beginUpdateTime
     * @param endUpdateTime
     * @param status
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_brand_tag_fuzzyQuery")
    public String fuzzyQuery(@RequestParam("tagName")String tagName,@RequestParam("beginUpdateTime")String beginUpdateTime,@RequestParam("endUpdateTime")String endUpdateTime,@RequestParam("status")String status,ModelMap modelMap){

        List<Wl_commodity_brand_tag> wl_commodity_brand_tagList=this.wl_commodity_brand_tagService.fuzzyQuery("%"+tagName+"%", beginUpdateTime, endUpdateTime, status);

        modelMap.addAttribute("wl_commodity_brand_tagList",wl_commodity_brand_tagList);

        return "table_wl_commodity_brand_tag";
    }

    /***
     * 新增品牌标签信息
     * @param wl_commodity_brand_tag
     * @return
     */
    @RequestMapping("wl_commodity_brand_tag_insertSelective")
    public String insertSelective(Wl_commodity_brand_tag wl_commodity_brand_tag){

        wl_commodity_brand_tag.setId(Math.random());
        wl_commodity_brand_tag.setCreateid(Math.random());
        wl_commodity_brand_tag.setCreatetime(new Date());

        int result=this.wl_commodity_brand_tagService.insertSelective(wl_commodity_brand_tag);

        return "redirect:wl_commodity_brand_tag_getAll";
    }

    /***
     * 修改品牌标签信息
     * @param wl_commodity_brand_tag
     * @return
     */
    @RequestMapping("wl_commodity_brand_tag_updateSelective")
    public String update(Wl_commodity_brand_tag wl_commodity_brand_tag){

        wl_commodity_brand_tag.setUpdatetime(new Date());
        wl_commodity_brand_tag.setUpdateid(Math.random());

        int result=this.wl_commodity_brand_tagService.updateByPrimaryKeySelective(wl_commodity_brand_tag);

        System.out.println(result);

        return "redirect:wl_commodity_brand_tag_getAll";
    }

    /***
     * 查询品牌标签详情
     * @param id
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_brand_tag_getById")
    public String getById(@RequestParam("id")String id,ModelMap modelMap){

        Wl_commodity_brand_tag wl_commodity_brand_tag=this.wl_commodity_brand_tagService.selectByPrimaryKey(id);

        modelMap.addAttribute("wl_commodity_brand_tag",wl_commodity_brand_tag);

        return "wl_commodity_brand_tag_update";
    }

    /***
     * 禁用品牌标签
     * @param id
     * @return
     */
    @RequestMapping("wl_commodity_brand_tag_delete")
    public String delete(@RequestParam("id")String id){

        Wl_commodity_brand_tag wl_commodity_brand_tag=this.wl_commodity_brand_tagService.selectByPrimaryKey(id);

        wl_commodity_brand_tag.setStatus(0);

        int result=this.wl_commodity_brand_tagService.updateByPrimaryKeySelective(wl_commodity_brand_tag);

        return "redirect:wl_commodity_brand_tag_getAll";
    }
}
